#ifndef ENEMYAI_H
#define ENEMYAI_H

#include "SensorRegion.h"
#include "Enemy.h"

#define DIVIDED_POINTS 8
#define UP_REGION 2
#define LEFT_REGION 4
#define DOWN_REGION 6

#define AI_DEFAULT_PRIORITY 10

#define NORMAL_RADIOS 3.5f
#define ARROW_RADIOS 4.0f
#define JAVELIN_RADIOS 3.8f
#define STONE_RADIOS 4.2f

#define TIME_NORMAL_ATTACK 0.1f
#define TIME_ARROW_ATTACK 0.12f
#define TIME_JAVELIN_ATTACK 0.14f
#define TIME_STONE_ATTACK 0.1f
#define TIME_TO_REFRESH 2.5f
#define AI_DELAY_TIME 0.15f

class LandPhysic;

class EnemyAI : public PhysicObject
{
public:
    EnemyAI();
    ~EnemyAI();

    void initEnemyAI(GamePlayScreen *pGameScreen, Enemy *pEnemy);    

    void createPhysicBody();
    void beginContact(b2Fixture *ownFixture, b2Fixture *otherFixture, b2Contact *contact);
    void endContact(b2Fixture *ownFixture, b2Fixture *otherFixture, b2Contact *contact);
    void removeObject();
    void update(float dt);

    static EnemyAI* createEnemyAI(ENEMY_TYPE eType, GamePlayScreen *pGameScreen, Enemy *pEnemy);

protected:
    void createRegions();
    char findRegionContainPoint(b2Vec2 pPoint);
    void checkAttackCondition();

    virtual void findBestRegion();
    virtual b2Vec2 findBestDirection();
    virtual b2Vec2 avoidHero();
    virtual void attackHero();

public:
    bool sawHero;
    char level;
    float radios, timeToAction, timeToAttack, attackDuration, timeToChangeDirect, refreshTime;
    char contactRegion;
    b2Vec2 heroPos, enemyPos;

    Enemy *enemyInstance;

    CCArray *regionList;
    SensorRegion *topRegion1, *topRegion2, *curRegion;

    CCArray *trapList;
    LandPhysic *safeLand;
};

#endif // ENEMYAI_H
